<?php
require_once('auth.php');

//Find the current session file
$login = $_SESSION['SESS_LOGIN'];
$target = "workspace/".$login;

//Receive GET value of the filename "name"

$realPath = realpath($target.'/'.$_GET['name']);
//Make sure filename path is good
$confirm = strpos($realPath, $_SERVER['DOCUMENT_ROOT'].'/REDCAT/'.$target.'/');

if ($confirm !== 0) die('Bad path!');

//Find the file's extension
$ext = end(split('.', $realPath));
if (strpos($realPath, '.redcat.') !== false) $ext = 'redcat';

//Begin download
header("Content-length: " . filesize($realPath));
header("Content-type: text/$ext");
header('Content-Disposition: attachment; filename="'.$_GET['name'].'"');

echo file_get_contents($realPath);
?>
